package com.xinchuang.controller.targetSystem.config;

import com.alibaba.fastjson.JSONObject;
import com.xinchuang.common.Result;
import com.xinchuang.common.ResultUtil;
import com.xinchuang.entity.targetSystem.config.SystemConfig;
import com.xinchuang.service.targetSystem.SystemElseService;
import com.xinchuang.service.targetSystem.config.SystemConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName ConfigController
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2022-08-09 10:15
 * @Verion V1.0
 */
@Api(value = "参数配置", tags = {"参数配置"})
@RestController
@RequestMapping(value = "/else")
public class ConfigController {

    /**
     * 新增/更新系统配置接口
     */
    private final String addOrUpdateSystemConfig = "/addOrUpdateSystemConfig";

    /**
     * 删除系统配置接口
     */
    private final String deleteSystemConfig = "/deleteSystemConfig";

    /**
     * 查询系统配置接口
     */
    private final String selectSystemConfig = "/selectSystemConfigs";

    /**
     * 统计
     */
    private final String statistics = "/statistics";

    /**
     * 资料信息
     */
    private final String dataMessage = "/dataMessage";

    /**
     * 标签管理
     */
    private final String signMessage = "/signMessage";

    /**
     * 新增修改作用范围类型
     */
    private final String addRangeType = "/addRangeType";

    /**
     * 删除作用范围类型
     */
    private final String deleteRangeType = "/deleteRangeType";

    /**
     * 查询作用范围类型
     */
    private final String getRangeType = "/getRangeType";

    /**
     * 复制粘贴类型或子类型ID
     */
    private final String copyTypeId= "/copyTypeId";

    /**
     * 复制粘贴类型或子类型属性
     */
    private final String copyType= "/copyType";

    @Resource
    private SystemConfigService systemConfigService;

    @Resource
    private SystemElseService systemElseService;

    @ApiOperation(value = "新增/更新系统配置接口")
    @PostMapping(value = addOrUpdateSystemConfig)
    public Result addOrUpdateSystemConfig(
            @RequestBody SystemConfig systemConfig
            ) {
        return systemConfigService.addOrUpdateSystemConfig(systemConfig);
    }

    @ApiOperation(value = "删除系统配置接口")
    @DeleteMapping(value = deleteSystemConfig)
    public Result deleteSystemConfig(
            @RequestParam(value = "id") String id
    ) {
        return systemConfigService.deleteSystemConfig(id);
    }

    @ApiOperation(value = "查询系统配置接口")
    @GetMapping(value = selectSystemConfig)
    public Result selectSystemConfig(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "isPull", defaultValue = "false") Boolean isPull
    ) {
        return systemConfigService.selectSystemConfig(pageNum, pageSize, isPull);
    }

    @ApiOperation(value = "统计接口")
    @GetMapping(value = statistics)
    public Result statistics(
            @RequestParam(value = "type", defaultValue = "1") Integer type,
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "radarNear", required = false, defaultValue = "10000") Integer radarNear,
            @RequestParam(value = "radarMiddle", required = false, defaultValue = "50000") Integer radarMiddle,
            @RequestParam(value = "radarFar", required = false, defaultValue = "100000") Integer radarFar,
            @RequestParam(value = "guidedNear", required = false, defaultValue = "10000") Integer guidedNear,
            @RequestParam(value = "guidedMiddle", required = false, defaultValue = "50000") Integer guidedMiddle,
            @RequestParam(value = "guidedFar", required = false, defaultValue = "100000") Integer guidedFar
    ) {
        return systemConfigService.selectStatistics(type, id, radarNear, radarMiddle, radarFar, guidedNear, guidedMiddle, guidedFar);
    }

    @ApiOperation(value = "资料信息录入接口")
    @PostMapping(value = dataMessage)
    public Result addDataMessage(
            @RequestBody JSONObject json
            ) {
        String targetId = json.getString("targetId");
        String subId = json.getString("subId");
        String id = json.getString("id");
        String name = json.getString("name");
        String url = json.getString("fileUrl");
        String remark = json.getString("remark");
        String fileList = json.getString("fileList");
        return systemConfigService.addDataMessage(targetId, subId, id, name, url, remark, fileList);
    }

    @ApiOperation(value = "资料信息删除接口")
    @DeleteMapping(value = dataMessage)
    public Result delDataMessage(
            @RequestParam(value = "id") String id
    ) {
        return systemConfigService.deleteDataMessage(id);
    }

    @ApiOperation(value = "资料信息查询接口")
    @GetMapping(value = dataMessage)
    public Result selectDataMessage(
            @RequestParam(value = "targetId", required = false) String targetId,
            @RequestParam(value = "subId", required = false) String subId,
            @RequestParam(value = "id", required = false) String id
    ) {
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(subId)) {
            return systemConfigService.selectDataMessageBySubId(targetId, subId);
        }
        if (StringUtils.isNotBlank(targetId)) {
            return systemConfigService.selectDataMessage(targetId);
        }
        if (StringUtils.isNotBlank(id)) {
            return systemConfigService.selectDataMessageById(id);
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "标签录入接口")
    @PostMapping(value = signMessage)
    public Result addSignMessage(
            @RequestBody JSONObject json
    ) {
        String targetId = json.getString("targetId");
        String subId = json.getString("subId");
        String id = json.getString("id");
        String name = json.getString("name");
        String address = json.getString("address");
        String reveal = json.getString("reveal");
        String icon = json.getString("icon");
        String remark = json.getString("remark");
        return systemConfigService.addSignMessage(targetId, subId, id, name, address, reveal, icon, remark);
    }

    @ApiOperation(value = "标签删除接口")
    @DeleteMapping(value = signMessage)
    public Result delSignMessage(
            @RequestParam(value = "id") String id
    ) {
        return systemConfigService.deleteSignMessage(id);
    }

    @ApiOperation(value = "标签查询接口")
    @GetMapping(value = signMessage)
    public Result selectSignMessage(
            @RequestParam(value = "targetId", required = false) String targetId,
            @RequestParam(value = "subId", required = false) String subId,
            @RequestParam(value = "id", required = false) String id
    ) {
        if (StringUtils.isNotBlank(targetId) && StringUtils.isNotBlank(subId)) {
            return systemConfigService.selectSignMessageBySubId(targetId, subId);
        }
        if (StringUtils.isNotBlank(targetId)) {
            return systemConfigService.selectSignMessage(targetId);
        }
        if (StringUtils.isNotBlank(id)) {
            return systemConfigService.selectSignMessageById(id);
        }
        return ResultUtil.success(null);
    }

    @ApiOperation(value = "新增修改作用范围类型")
    @PostMapping(value = addRangeType)
    public Result addRangeType(@RequestBody JSONObject json) {
        return systemElseService.addRangeType(json);
    }

    @ApiOperation(value = "删除作用范围类型")
    @PostMapping(value = deleteRangeType)
    public Result deleteRangeType(@RequestBody JSONObject json) {
        return systemElseService.deleteRangeType(json);
    }

    @ApiOperation(value = "查询作用范围类型")
    @PostMapping(value = getRangeType)
    public Result getRangeType(@RequestBody JSONObject json) {
        return systemElseService.selectRangeType(json);
    }

    @ApiOperation(value = "复制粘贴类型或子类型属性")
    @PostMapping(value = copyType)
    public Result copyType(
            @RequestBody JSONObject json
    ) {
        return systemConfigService.copyTypeOrSubType(json);
    }

}